<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>系统推送</title>
    <#include "../common/header.ftl"/>
    <script type="text/javascript" src="/ckeditor/ckeditor.js"></script>
    <script type="text/javascript">
        $(function () {
            // 富文本编辑器
            var ckeditor = CKEDITOR.replace( 'content', {
                filebrowserBrowseUrl: '并没有图片服务器',
                filebrowserUploadUrl: '/images/upload.do'
            });

            // 推荐数据回显
            var content;
            $('.inputBtn').click(function() {
                $('#editForm')[0].reset();
                content = ckeditor.setData("");
                $('#editForm img').attr('src', '');
                var data = $(this).data('json');
                if (data) {
                    $('#editForm input[name="id"]').val(data.id);
                    $('#editForm input[name="title"]').val(data.title);
                    $.get('/sysnotice/getContentByNoticeId.do',{noticeId:data.id},function (data) {
                        console.log(data);
                        var content = ckeditor.setData(data.content);
                        $("#content").html(content);
                    });
                }

                $('#editModal').modal('show');
            });

            // 图片更换是回显
            $('#editForm input[name="file"]').change(function () {
                // 创建文件读取器对象
                var read = new FileReader();
                // 读取文件内容
                read.readAsDataURL(this.files[0]);
                // 将用户选择的图片渲染到页面
                $(read).load(function () {
                    $('#editForm img').attr('src',read.result);
                });
                // $('#editForm img').attr('src',window.URL.createObjectURL(this.files[0]));
            });
            // 保存操作
            $('.btn_submit').click(function () {
                $('#content').html(ckeditor.getData());
                $('#editForm').ajaxSubmit(function (data) {
                    if(data.success){
                        window.location.reload();
                    }
                })
            });

            //  查询操作
            $("btn").click(function () {

            })

        });
    </script>

</head>

<body>
<div class="container">
<#include "../common/top.ftl"/>
    <div class="row">
        <div class="col-sm-3">
		<#assign currentMenu = "notice" />
				<#include "../common/menu.ftl" />
        </div>
        <div class="col-sm-9">
            <div class="page-header">
                <h3>推送管理</h3>
            </div>
            <div class="row">
                <!-- 提交分页的表单 -->
                <form id="searchForm" class="form-inline" method="post" action="/sysnotice/list.do">
                    <input type="hidden" name="currentPage" id="currentPage" value="1"/>
                    <div class="form-group">
                        <label>推送标题搜索</label>
                        <input type="text" name="keyword" value="${qo.keyword!}">
                    </div>
                    <div class="form-group">
                        <button id="query" class="btn btn-success"><i class="icon-search"></i> 查询</button>
                        <button type="button" class="btn btn-success inputBtn"><i class="icon-plus"></i> 推送消息</button>
                    </div>
                </form>
            </div>
            </br>
            <div class="row">
                <table class="table">
                    <thead>
                    <tr>
                        <th>序号</th>
                        <th>标题</th>
                        <th>推送时间</th>
                        <th>发布人</th>
                    </tr>
                    </thead>
                    <tbody>

                    <#if result ??>
                    <#list result.list as n>
                     <tr>
                    <td>${n_index+1}</td>
                    <td>${n.title!}</td>
                    <td>${(n.releasetime?string("yyyy-MM-dd"))!}</td>
                    <td>${n.releasename!}</td>
                    <td>
                        <a href="javascript:;"  class="btn btn-success inputBtn" data-json='${n.jsonString!}'>查看推送</a>
                    </td>
                     </tr>
                    </#list>
                    </#if>

                    </tbody>
                </table>
                <div style="text-align: center;">
                    <ul id="pagination" class="pagination"></ul>
                </div>
                <#include "../common/page.ftl">
            </div>
        </div>
    </div>
</div>
<div class="modal fade" id="editModal">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title">推送</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/sysnotice/saveOrUpdate.do" method="post" id="editForm" >
                    <input type="hidden" value="" name="id">
                    <div class="form-group" id="parentDiv">
                        <label class="col-sm-3 control-label">标题：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="title">
                        </div>
                    </div>

                    <div class="form-group">
                        <div class="col-sm-12">
                            <textarea name="content" id="content" class="ckeditor" rows="10" cols="80">

                            </textarea>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary btn_submit">推送</button>
                <button type="button" class="btn btn-danger" data-dismiss="modal">取消</button>
            </div>
        </div>
    </div>
</div>
</body>
</html>